modified DoctrineWriter's setValue to check for manyToMany add methods#124
modified DoctrineWriter's setValue to check for manyToMany add methods#124intrepion wants to merge 2 commits intoddeboer:masterfrom
Conversation
|
Interesting! Could you update DoctrineWriter docs too? |
|
Sure thing! |
|
Great! If you could do so in this PR, I’ll merge everything in one go. |
|
Really cool 👍 |
|
@intrepion @ddeboer Any news on this? I kindof need this. |
|
I've fixed this by adding a setter on my many to many relation, so no need to hurry anymore ;) |
|
I'm interested in this PR. There is just missing documentation for it to be merged ? |
|
Could you please rebase this on master so we can merge this? |
Conflicts: src/Writer/DoctrineWriter.php tests/Writer/DoctrineWriterTest.php
|
I almost wrote something similar by myself. But now that I've found this I'm wondering when it will be merged? Update: Tried to copy/paste setValue(...). Doesn't seem to work out of box right now. Also, when defining a $setter variable inside the function, wouldnt it make obsolte to provide such a variable to the function as an argument? Update2: /**
* Call a setter of the entity
*
* @param object $entity
* @param mixed $value
* @param string $fieldName
*/
protected function setValue($entity, $value, $fieldName)
{
$getter = 'get' . ucfirst($fieldName);
$setter = 'set' . ucfirst($fieldName);
$adder = 'add' . ucfirst($fieldName);
$remover = 'remove' . ucfirst($fieldName);
if (method_exists($entity, $setter))
{
$entity->$setter($value);
}
elseif (method_exists($entity, $adder))
{
$oldValue = $entity->$getter();
if ($oldValue)
{
foreach ($oldValue as $oldItem)
{
$entity->$remover($oldItem);
}
}
if (is_array($value))
{
foreach ($value as $newItem)
{
$entity->$adder($newItem);
}
}
else
$entity->$adder($value);
}
} |
This PR is for allowing DoctrineWriter to handle updating many-to-many and one-to-many associations that use
addandremovemethods. The unit tests have also been updated.